<template>
    <view class="content">
        <view class="input-group">
            <view class="input-row border">
                <text class="title">账号：</text>
                <m-input type="text" focus clearable v-model="account" placeholder="请输入账号"></m-input>
            </view>
            <view class="input-row border">
                <text class="title">密码：</text>
                <m-input type="password" displayable v-model="password" placeholder="请输入密码"></m-input>
            </view>
            <view class="input-row">
                <text class="title">确认密码：</text>
                <m-input type="password" displayable v-model="rpassword" placeholder="请确认输入密码"></m-input>
            </view>
        </view>
        <view class="btn-row">
            <button type="primary" class="primary" @tap="register">注册</button>
        </view>
    </view>
</template>

<script>
    import {api_login_reg} from '@/api/login.js';
    import mInput from '../../components/m-input.vue';
	
    export default {
        components: {
            mInput
        },
        data() {
            return {
                account: '',
                password: '',
				rpassword:'',
                email: ''
            }
        },
        methods: {
            register() {
                /**
                 * 客户端对账号信息进行一些必要的校验。
                 * 实际开发中，根据业务需要进行处理，这里仅做示例。
                 */
                if (this.account.length < 5) {
                    uni.showToast({
                        icon: 'none',
                        title: '账号最短为 5 个字符'
                    });
                    return;
                }
                if (this.password.length < 6) {
                    uni.showToast({
                        icon: 'none',
                        title: '密码最短为 6 个字符'
                    });
                    return;
                }
				if(this.rpassword!== this.password){
					uni.showToast({
					    icon: 'none',
					    title: '请确认2次密码输入正确'
					});
					return;
				}
                /* if (this.email.length < 3 || !~this.email.indexOf('@')) {
                    uni.showToast({
                        icon: 'none',
                        title: '邮箱地址不合法'
                    });
                    return;
                } */

                const data = {
                    username: this.account,
                    password: this.password
                }
                api_login_reg(data).then(res=>{
								
					if (res.data.code===0){
						 uni.navigateBack()
					}else{
						uni.showToast({ title: res.data.msg});
					}
				});
            }
        }
    }
</script>

<style>

</style>
